#Boa:Dialog:Dialog1

import wx
import consultasBD
import utiles

def create(parent):
    return Dialog1(parent)

[wxID_DIALOG1, wxID_DIALOG1BUTTON1, wxID_DIALOG1COMBOBOXSUC, 
 wxID_DIALOG1PANEL1, wxID_DIALOG1SUCURSAL, 
] = [wx.NewId() for _init_ctrls in range(5)]

class Dialog1(wx.Dialog):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Dialog.__init__(self, id=wxID_DIALOG1, name='', parent=prnt,
              pos=wx.Point(434, 139), size=wx.Size(401, 93),
              style=wx.DEFAULT_DIALOG_STYLE, title='Sucursales')
        self.SetClientSize(wx.Size(393, 66))

        self.panel1 = wx.Panel(id=wxID_DIALOG1PANEL1, name='panel1',
              parent=self, pos=wx.Point(0, 0), size=wx.Size(423, 112),
              style=wx.TAB_TRAVERSAL)

        self.comboBoxSuc = wx.ComboBox(choices=[], id=wxID_DIALOG1COMBOBOXSUC,
              name='comboBoxSuc', parent=self.panel1, pos=wx.Point(16, 24),
              size=wx.Size(280, 21), style=0, value='')
        self.comboBoxSuc.SetLabel('')

        self.button1 = wx.Button(id=wxID_DIALOG1BUTTON1, label='Aceptar',
              name='button1', parent=self.panel1, pos=wx.Point(320, 24),
              size=wx.Size(56, 23), style=0)
        self.button1.Bind(wx.EVT_BUTTON, self.OnBotonAceptar,
              id=wxID_DIALOG1BUTTON1)

        self.sucursal = wx.StaticText(id=wxID_DIALOG1SUCURSAL,
              label='Sucursal Destino', name='sucursal', parent=self.panel1,
              pos=wx.Point(16, 8), size=wx.Size(79, 13), style=0)

    def __init__(self, parent):
        self._init_ctrls(parent)
        self.padre = parent
        self.eleccion = ""
        self.cargaCombo()
        
    def cargaCombo(self):
        sql = "SELECT codsucursal,nombre FROM sucursales WHERE activa = 0"
        resultados = consultasBD.ordenCruda(sql)
        #aux = resultados[0][0]
        for sucu in resultados:
            item = sucu[0]+" / "+sucu[1]
            self.comboBoxSuc.Append(item)
            self.eleccion = item
        self.comboBoxSuc.SetLabel(self.eleccion)
        self.eleccion = self.eleccion.split()[0]

    def OnBotonAceptar(self, event):
        self.sucElegida,self.sucNombre = self.comboBoxSuc.GetValue().split(" / ")
        self.Close()
        
    def getEleccion(self):
        return self.sucElegida,self.sucNombre
    
    
